class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        stack<int> st;
        int len =temperatures.size();
        int i=0;
        vector<int> ret(temperatures.size());
        while(i<len)
        {
            while(!st.empty()&&temperatures[i]>temperatures[st.top()])
            {
                int index = st.top();
                ret[index] =i-index;
                st.pop();
            }
            st.push(i);
            i++;
        }
        return ret;
    }
};
